package utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.media.MediaPlayer;

import com.example.administrator.newxlmedical.R;

import constants.Constants;

/**
 * Created by Administrator on 2018/11/14.
 */

public class MediaPlayerUtils {

    private static MediaPlayer mediaPlayer;

    public static void playSound(Context mContext, int source){
        SharedPreferences sharedPreferences = ActivityUtil.getSharedPreferences(mContext);
        int sound = sharedPreferences.getInt(Constants.SOUND_KEY, 50);
        Float div = FormateUtils.div(sound, 100, 1);

        if (mediaPlayer != null){
            mediaPlayer.release();
        }
        mediaPlayer = MediaPlayer.create(mContext, source);
        mediaPlayer.setVolume(div,div);
        mediaPlayer.start();
    }
    public static void stop(){
        if (mediaPlayer != null){
            mediaPlayer.stop();
        }
    }
}
